import json
import random

import requests

from faker import Faker


lastItem=1
for itemId in range(1,121):  #range(1,121) random.sample(range(1,717),300)
    lastItem = itemId
    urlReplySave = 'http://127.0.0.1:8081/api/front/community/visitRecord/save'
    # headers = {'Authorization': PEXELS_API_KEY}
    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.188 Safari/537.36 CrKey/1.54.250320',
        'Authori-Zation': 'd8bed6776ecb49fdb6a734c5cc86653e',
        'Content-Type': 'application/json'
    }
    for x in range(random.randint(0,6)): #每一个评论插入0-10条浏览记录
        #       评分数据
        jsonComment = '{"pid": 2,"uid":0}'
        productComment = json.loads(jsonComment)
        productComment['pid'] = itemId
        productComment['uid']=x+230
        productComment = json.dumps(productComment)
        # 插入item评分*******************
        response = requests.post(urlReplySave, data=productComment, headers=headers)
        if response.status_code == 200:
            data = response.json()
            # print(data)
            if data['code'] == 200:
                print(f"插入{itemId}成功")
            else:
                print(f"插入{itemId}评论失败,code!=200")
        else:
            print(f"插入{itemId}评论失败,无响应")
        # 评分*******************


print('++++++++++++++++++++++++++++++++')
re={
    '插入到postId,':lastItem
}
print(re)
# 数据库出错了，
with open('./re/insetResult_Comment' + str(1) + '.json', 'w', encoding='utf-8') as f:
    json.dump(re, f, ensure_ascii=False, indent=4)
# # 获取第5行数据，行索引号为4
# row_index = 99999
# row_data = data.iloc[row_index]
# # 打印第5行数据
# print(type(row_data))
# print(row_data)
# print(row_data['userID'])

#它大爷的 后面发现其实它的电影ID就是1-1682 所以干脆直接插入电影就好了，，压根不需要读取交互文件  操他吗的、日 浪费老子电脑何时间
